// pages/me/me.js
let app = getApp()
const service = require('../../utils/service.js')
const api = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    orderCount: '',
    shop_user_id: '',
    isManager: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.init()
  },

  init: function () {
    let that = this
    that.setData({
      userInfo: wx.getStorageSync('shop_data'),
      shop_user_id: wx.getStorageSync('out_user_id')
    })
    that.getShopManageUser()
    that.getOrderCount()
  },

  //获取商店管理人权限
  getShopManageUser: function(){
    let that = this;
    api.ajax(service.url('getShopManageUser'),{
      out_user_id: this.data.userInfo.out_user_id
    },function(res){
      console.log(res)
      that.setData({
        isManager: res.data.is_manager
      })
    })
  },

  getOrderCount: function () {
    let that = this
    api.ajax(service.url('personalCenterStatistics'), {}, function (res) {
      if (res.code == 0) {
        that.setData({
          orderCount: res.data
        })
      } else {
        api.toast(res.message)
      }
    })
  },

  goOpenShop: function(){
    let isOpenShop = wx.getStorageSync('shop_data').is_store == 0 ? false : true;
    let popIsShop = wx.getStorageSync('shop_data').is_store == 0 ? true : false;

    wx.navigateTo({
      url: `../my_shop/my_shop`
    })
    
  },

  // 前往订单列表
  toOrder: function (e) {
    var type = e.currentTarget.dataset.type
    wx.navigateTo({
      url: `../order/order?type=${type}`
    })
  },
  
  // 前往优惠券
  toCoupon: function () {
    wx.navigateTo({
      url: '../coupon/coupon'
    })
  },

  // 前往我的收藏
  toCollect: function () {
    wx.navigateTo({
      url: '../collect/collect'
    })
  },

  // 前往我的足迹
  toFootPrint: function () {
    wx.navigateTo({
      url: '../footprint/footprint'
    })
  },

  // 前往我的评价
  toComment: function () {
    wx.navigateTo({
      url: '../comment/comment'
    })
  },

  // 前往收货地址
  toAddress: function () {
    wx.navigateTo({
      url: '../address/address'
    })
  },

  // 前往推荐分成
  toDivide: function () {
    wx.navigateTo({
      url: '../divide/divide'
    })
  },

  onPullDownRefresh: function () {
    wx.showNavigationBarLoading()
    this.getOrderCount()
    setTimeout(() => {
      wx.hideNavigationBarLoading()
      wx.stopPullDownRefresh()
    }, 1500)
  },
})